

import csv
#数据驱动
import yaml


def read_csv_for_parametrize(file_path):
    params = []
    with open(file_path, 'r', newline='', encoding='utf-8') as file:
        reader = csv.DictReader(file)
        for row in reader:
            username = row['username']
            password = row['password']
            expected = row['exp']
            params.append((username, password, expected))
    return params


def read_yaml(file_path):
    params = []
    with open(file_path, 'r', encoding='utf-8') as file:
        data = yaml.load(file,Loader=yaml.UnsafeLoader)
        cases = data.get('case_login', {})
        for case in cases.values():
            username = case['username']
            password = case['password']
            expected = case['exp']
            params.append((username, password, expected))
        # print(params)
    return params

def read_local_yaml(file_path):
    params = []
    with open(file_path, 'r', encoding='utf-8') as file:
        data = yaml.load(file,Loader=yaml.UnsafeLoader)
        cases = data.get('case_local', {})
        for case in cases.values():
            name = case['name']
            Driver_1 = case['Driver_1']
            Driver_path_1 = case['Driver_path_1']
            exp = case['exp']
            params.append((name, Driver_1, Driver_path_1,exp))
        # print(params)
    return params

def read_s3_yaml(file_path):
    params = []
    with open(file_path, 'r', encoding='utf-8') as file:
        data = yaml.load(file,Loader=yaml.UnsafeLoader)
        cases = data.get('case_s3', {})
        for case in cases.values():
            name = case['name']
            adress = case['adress']
            username = case['username']
            password  = case['password']
            exp_test = case['exp_test']
            exp_save = case['exp_save']
            params.append((name, adress, username,password,exp_test
                           ,exp_save))
        # print(params)
    return params
def read_ftp_yaml(file_path):
    params = []
    with open(file_path, 'r', encoding='utf-8') as file:
        data = yaml.load(file,Loader=yaml.UnsafeLoader)
        cases = data.get('case_ftp', {})
        for case in cases.values():
            name = case['name']
            host = case['host']
            port = case['port']
            username = case['username']
            password  = case['password']
            exp_test = case['exp_test']
            exp_save = case['exp_save']
            params.append((name, host,port, username,password,exp_test
                           ,exp_save))
        # print(params)
    return params


def read_remote_yaml(file_path):
    params = []
    with open(file_path, 'r', encoding='utf-8') as file:
        data = yaml.load(file,Loader=yaml.UnsafeLoader)
        cases = data.get('case_remote', {})
        for case in cases.values():
            name = case['name']
            host = case['host']
            port = case['port']
            username  = case['username']
            password = case['password']
            max_conn = case['max_conn']
            exp_test = case['exp_test']
            exp_save = case['exp_save']
            params.append((name, host, port,username,password,max_conn,exp_test
                           ,exp_save))
        # print(params)
    return params


#
if __name__ == '__main__':
    read_local_yaml('../data/local_case.yaml')